set savedGameGlobals to [#gStates: "a dynamic list of the current state of the game.", #gSoundChannels: "a dynamic list of the current state of sound.", #gsoundLevel: "sound level.", #gCDNotes: "a hit record from the radiostation.", #gNotesToPlay: "the radiostation notes before a CD is cut.", #gNotes: "the radiostation notes before a CD is cut.", #gMidiManager: "something", #gMidiStartTime: "something", #gMidiInstruments: "something"]
set savedGameData to dumpGlobals(savedGameGlobals)
set fileData to ChaosVersionString()
put string(savedGameData) into line 2 of fileData
set promptForName to 0
if saveData(saveFileName, fileData, promptForName) then
if getOne(gScreenState, #SaveDialogBox) > 0 then
CloseSaveUNVDialog()
end if
if getaProp(getaProp(gOBJECTS, #QuitYetDialog), #gQuitAfter) = 1 then
halt()
end if
else
displayChaosError(#warning, "There was an error writing to the file. Please save your game under another name and quit")
end if
end
on loadGameData
global gStates
set saveFileName to line 1 of field getaProp(getaProp(getaProp(gOBJECTS, #SaveNameText), #cast), #text)
set promptForName to 0
set savedGameData to loadData(saveFileName, promptForName)
if (savedGameData <> EMPTY) and not voidp(savedGameData) then
if line 1 of savedGameData = ChaosVersionString() then
delete line 1 of savedGameData
restoreGlobals(savedGameData)
massagegStatesOnOpen()
return 1
else
displayChaosError(#severe, "This file does not contain saved Chaos game data, or is old or damaged.")
return 0
end if
else
put "Couldn't get any data from the file. Something's screwed up."
return 0
end if
put "Something's screwed up."
end
on ChaosVersionString
set fileData to "Gray Matter Studios, version 11. kam stewart, system architect"
return fileData
end
on ChaosPrefVerification
set Data to "program preferences"
return Data
end
on SetPrefFilename
set prefFileName to "CHAOS" & "." & prefDataType()
return prefFileName
end
on savePrefData
global myMidiDevice, gLimitPreLoad
set saveFileName to SetPrefFilename()
if voidp(myMidiDevice) then
set myMidiDevice to voidDatasymbol()
end if
if voidp(gLimitPreLoad) then
set gLimitPreLoad to voidDatasymbol()
end if
set ChaosGlobal to [#myMidiDevice: myMidiDevice, #gLimitPreLoad: gLimitPreLoad]
set diskSpace to miscXobj(mSpaceOnVol, volumeName)
if diskSpace < 80000 then
displayChaosError(#warning, "Your disk is too full to save your Chaos game data. There are only" && string(diskSpace) && "bytes remaining on drive" && volumeName & ".")
exit
end if
if miscXobj(mFileExists, savedFilesPath & gfileSep & saveFileName) then
if objectp(myFileIO) then
myFileIO(mdispose)
end if
set myFileIO to FileIO(mnew, "read", savedFilesPath & gfileSep & saveFileName)
myFileIO(mDelete)
end if
if objectp(myFileIO) then
myFileIO(mdispose)
end if
if promptForName then
if objectp(saveDataObj) then
saveDataObj(mdispose)
end if
if the machineType = 256 then
set saveDataObj to movUtils(mnew)
else
set saveDataObj to MovieUtilities(mnew)
end if
saveDataObj(mSetDefaultPath, savedFilesPath)
set myFileIO to FileIO(mnew, "?write", saveFileName)
saveDataObj(mdispose)
else
put savedFilesPath & gfileSep & saveFileName
set myFileIO to FileIO(mnew, "write", savedFilesPath & gfileSep & saveFileName)
end if
if objectp(myFileIO) then
if gCPU = #MAC then
myFileIO(mSetFinderInfo, saveDataType(), "ttxt")
end if
myFileIO(mWriteString, fileData)
if objectp(myFileIO) then
myFileIO(mdispose)
end if
return 1
else
if not voidp(myFileIO) then
if myFileIO <> -43 then
set errMsg to getaProp(IOerrors, abs(myFileIO))
if voidp(errMsg) then
displayChaosError(#warning, "An error occurred while saving your Chaos game data:" & RETURN & RETURN & "Code" && string(myFileIO))
else
displayChaosError(#warning, "An error occurred while saving your Chaos game data:" & RETURN & RETURN & errMsg)
end if
end if
else
displayChaosError(#warning, "void instance of fileIO.")
end if
if objectp(myFileIO) then
myFileIO(mdispose)
end if
return 0
end if
end
on makeDOSfilename str
set theCount to length(str)
set theResult to EMPTY
repeat with X = 1 to theCount
set theChar to char X of str
if "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_" contains theChar then
put theChar after theResult
end if
end repeat
return theResult
end
on saveDataType
if gCPU = #MAC then
set signature to "KAOS"
else
set signature to "SVG"
end if
return signature
end
on prefDataType
set signature to "PRF"
return signature
end
on voidDatasymbol
set voidsymbol to [#void]
return voidsymbol
end
on LoadXObjects
set IOerrors to [33: "File directory full", 34: "Volume full", 35: "Volume not found", 36: "I/O Error", 37: "Bad file name", 38: "File not open", 42: "Too many files open", 43: "File not found", 49: "File open with write permission", 56: "No such drive", 65: "No disk in drive", 120: "Directory not found"]
if the machineType = 256 then
set cpu to #mpc
openXLib(gCodePath & "FILEIO.DLL")
openXLib(gCodePath & "MovUtils.DLL")
openXLib(gCodePath & "MISC_X.DLL")
else
set cpu to #MAC
if not objectp(factory("MovieUtilities XObj")) then
openXLib(gCodePath & "MovieUtilities XObj")
end if
if not objectp(factory("Misc_X XObj")) then
openXLib(gCodePath & "Misc_X XObj")
end if
if not objectp(factory("PlayNote.Xobj")) then
openXLib(gCodePath & "PlayNote.Xobj")
end if
end if
end
on savePreferences
global myMidiDevice, gLimitPreLoad
set prefsGlobals to [#myMidiDevice: "the midi driver the user chooses", #gLimitPreLoad: "Turbo-mode, if off skips preLoad on large frames"]
set prefsData to dumpGlobals(prefsGlobals)
saveData("CHAOS.PRF", string(prefsData))
end
on deleteGame whichGame
global savedFilesPath, gfileSep
if miscXobj(mFileExists, savedFilesPath & gfileSep & whichGame) then
if objectp(myFileIO) then
myFileIO(mdispose)
end if
set myFileIO to FileIO(mnew, "read", savedFilesPath & gfileSep & whichGame)